package com.dxd.onlineshop.controller;

import com.dxd.onlineshop.service.SystemSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/admin/settings")
@Slf4j
public class SystemSettingController {

    @Autowired
    private SystemSettingService systemSettingService;

    @GetMapping
    public ResponseEntity<Map<String, Object>> getAllSettings() {
        log.info("正在获取所有系统设置");
        Map<String, Object> settings = systemSettingService.getAllSettings();
        log.info("成功获取系统设置: {}", settings);
        return ResponseEntity.ok(settings);
    }

    @PutMapping
    public ResponseEntity<String> updateSettings(@RequestBody Map<String, Object> settings) {
        log.info("正在更新系统设置: {}", settings);
        systemSettingService.updateSettings(settings);
        log.info("系统设置更新成功");
        return ResponseEntity.ok("设置已更新");
    }
}